﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using theeg.DependencyAnalysis.CommonAddin.Models;
using Thread = System.Threading.Thread;

namespace IntegrationTests
{
    [TestClass]
    public class AddinModelTest
    {
        [TestMethod]
        public void AddinCommunicatesWithAnalysisHost()
        {
            var modules = new[] { typeof(ClassLibrary1.Class1).Assembly.Location };
            const string pipeName = "AddinModelTest";
            var analysisHost = new AnalysisHost.App();
            var clientThread = new Thread(() => analysisHost.ProcessPipeClient(pipeName));

            var addin = new AddinModel(new SolutionStub());
            var serverThread = new Thread(() => addin.StartAnalysis(modules, true, pipeName));
            serverThread.Start();
            Thread.Sleep(100);
            clientThread.Start();
            serverThread.Join();

            Assert.IsNotNull(addin.DependencyModel);
            Assert.IsNotNull(addin.Metrics);
        }
    }
}
